package com.sumainfor.pc.market.service;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.utlis.ListMapRepeat;
import com.sumainfor.pc.market.dao.CommunityMapper;
import com.sumainfor.pc.market.dao.ProvinceMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 功能描述:
 * 省份
 *
 * @Auther: zhlu
 * @Date: 2019/3/11 17:56
 * @Description:
 */
@Service
public class ProvinceService {
    Logger log = LoggerFactory.getLogger(CityService.class);

    @Autowired
    ProvinceMapper ProvinceMapper;

    @Autowired
    CommunityMapper CommunityMapper;

    /**
     * 功能描述:
     * 获取所有的省份
     *
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/11 17:59
     */
    public List<Map<String, Object>> getProvinceList(Map<String, Object> params) {
        //数据拦截类型   all不拦截    term项目已有省市区
        if (FieldCheckUtil.isMapFieldNotNull(params, new String[]{"stemDataType"})) {
            if (params.get("stemDataType").equals("term") || params.get("stemDataType").toString() == "term") {
                //获取现有项目的省市区
                List<Map<String, Object>> getCommunityTermList = CommunityMapper.getCommunityTermList(params);
                log.info("getCommunityTermList----" + getCommunityTermList);
                //接收去重之后的数据
                List<Map<String, Object>> ComList = ListMapRepeat.removeRepeatMapByKey(getCommunityTermList, "ProvinceID");
                //重新组成String集合in查询
                List<String> ProvinceNameList = new ArrayList<>();
                if (ComList != null && ComList.size() > 0) {
                    for (Map<String, Object> map : ComList) {
                        ProvinceNameList.add(map.get("ProvinceID").toString());
                    }
                    params.put("ProvinceList", ProvinceNameList);
                } else {
                    return ComList;
                }
            }
        }
        List<Map<String, Object>> getProvinceList = ProvinceMapper.getProvinceList(params);
        return getProvinceList;
    }

}
